/*!
 * \file test_json.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2017/03/07
 *
 */

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <pthread.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "../../src/module/json/config.h"

#include "t_json_data_analyze/t_json_data_analyze.h"

static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, "apmcomm") == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    //t_json_data_analyze
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_get_type);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_bool_and_str_report);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_integer_report);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_double_report);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_map_report);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_list_and_set_report);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_value_report);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_read_fields);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_json_analyze);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_frthrift_data_detect);

    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();

    fr_slab_destroy();

    return 0;
}
